<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<div class="mainbar">
	<div class="page-head">
		<h2 class="pull-left">
			<i class="icon-tasks"></i>
			<spring:message code="menu.addNews.label" />
		</h2>
		<div class="clearfix"></div>

	</div>
	<div class="matter background_seller">
		<div class="container-fluid">
			<div class="row-fluid">
				<div class="span">
					<div class="widget">
						<div class="widget-head">
							<div class="pull-left">
								<spring:message code="menu.newsinfo.label" />
							</div>
							<div class="clearfix"></div>
						</div>
						<div class="widget-content">
							<div class="padd">
								<!-- 								<div class="offset1"> -->
								<form:form id="addNewsForm" action="addNews" method="POST"
									class="form-horizontal" modelAttribute="news"
									enctype="multipart/form-data">
									<!-- Username -->
									<div class="control-group">
										<label class="control-label admin_Label" for="newsname"><spring:message
												code="menu.newsname.label" /></label>
										<div class="controls">
											<form:input type="text" class="input-large" style="width: 700px"
												name="txtnewsname" id="newsname" path="name" />
										</div>
									</div>
									<div class="control-group">
										<label class="control-label admin_Label" for="newsshortdesc"><spring:message
												code="menu.newsshortdesc.label" /></label>
										<div class="controls">
											<form:textarea class="input-large"
												 name="txtnewsshortdesc" style="width: 700px; height: 100px;"
												id="newsshortdesc" path="shortdescvi" />

										</div>
									</div>
									<div class="control-group">
										<label class="control-label admin_Label" for="newsshortdesc">Tải
											Hình Lên Server</label>
										<div class="controls">

											<a href="#uploadFile" role="button" data-toggle="modal"
												class="btn "> Tải Hình </a>
										</div>
									</div>									
									<div class="control-group">
										<label class="control-label admin_Label"
											style="margin-right: 0px" for="newsfulldesc"><spring:message
												code="menu.newsfulldesc.label" /></label>
										<div class="controls" style="margin-left: 180px">

											<form:textarea cols="30" rows="10" class="input-large"
												name="newsfulldesc" id="newsfulldesc" path="fulldescvi" />

											<%-- 											<ckeditor:replace replace="newsfulldesc" basePath="/ckeditor/" /> --%>
										</div>
									</div>
									<div class="control-group">
										<label class="control-label admin_Label" for="newsenshortdesc"><spring:message
												code="menu.newsenshortdesc.label" /></label>
										<div class="controls">
											<form:textarea  class="input-large"
												style="width: 700px; height: 100px;" name="txtnewsenshortdesc"
												id="newsenshortdesc" path="shortdescen" />

										</div>
									</div>
									<div class="control-group">
										<label class="control-label admin_Label"
											style="margin-right: 0px" for="newsenfulldesc"><spring:message
												code="menu.newsenfulldesc.label" /></label>
										<div class="controls" style="margin-left: 180px">
											<form:textarea cols="100" rows="10" class="input-large"
												name="txtnewsenfulldesc" id="newsenfulldesc"
												path="fulldescen" />

											<%-- 													<ckeditor:replace replace="newsenfulldesc" basePath="/ckeditor/" /> --%>
										</div>
									</div>
									
										<div class="control-group">
										<label class="control-label admin_Label" for="newsimage"><spring:message
												code="menu.newsimage.label" /></label>
										<div class="controls">
											<input type="file" class="input-large"
												accept="gif|jpeg|bmp|png|jpg" size="50" name="newsimage"
												id="newsimage">
										</div>
									</div>
								
									<div class="control-group">
										<label class="control-label admin_Label" for="isActive"><spring:message
												code="menu.isActive.label" /></label>
										<div class="controls">
											<form:checkbox name="isActive" value="false" path="isActive" />
										</div>
									</div>


									<input type="hidden" value="0" id="currentFieldCount" />

									<div class="control-group">
										<div class="controls">

											<button type="submit" class="btn btn-primary offset2"
												value="addNews" name="action">
												<spring:message code="menu.addNew.label" />
											</button>
											<a href="./listNews" class="btn btn-primary "
												style="font-size: 12px !important; margin-left: 20px"><spring:message
													code="menu.cancel.label" /></a>
										</div>
									</div>
								</form:form>
								<!-- 								</div> -->
							</div>
						</div>
					</div>
				</div>
				<div id="uploadFile" class="modal fade">
					<div class="modal-dialog">
						<div class="modal-content">
							<div class="modal-header">
								<button type="button" class="close" data-dismiss="modal"
									aria-hidden="true">×</button>
								<h4>Upload File</h4>
							</div>
							<div class="modal-body">
								<div class="form">
									<h3>Chọn hình để tải lên Server</h3>
										<input type="file" class="input-large"
											accept="gif|jpeg|bmp|png|jpg" size="50" name="uploadfile"
											id="uploadfile" />
										<input type="submit" value="upload" id="submitFile"
											onclick="getImageUrl();" />
								</div>
																	
										<div class="control-group">
											<label class="control-label admin_Label" for="newsshortdesc">Đường
												link hình ảnh</label>
											<div class="controls">
												<div id="showLink"></div>

											</div>
										</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
	function getImageUrl() {
		var xmlHttp = getXMLObject();
		if (xmlHttp) {
			var imgFile = document.getElementById("uploadfile").files[0];
			var formData = new FormData();
			var showLink = document.getElementById("showLink");
			formData.append("imgFile", imgFile);		
			xmlHttp.open("POST", "../admin/uploadFile", true);
			xmlHttp.setRequestHeader("contentType", "multipart/form-data");
			xmlHttp.send(formData);
			xmlHttp.onreadystatechange  = function() {
				if (xmlHttp.readyState == 4) {
					if (xmlHttp.status == 200) {
						if (xmlHttp.responseText != "") {
							showLink.innerHTML = xmlHttp.responseText;
						}
					}
				}
			};
		} else {
			alert('Your browser does not support AJAX!');
		}
	}

	CKEDITOR.replace('newsfulldesc', {
		fullPage : true,
		allowedContent : true,
		language : 'vi',

	});
	CKEDITOR.replace( 'newsenfulldesc', {
		fullPage: true,
		allowedContent: true,
		language: 'vi',

	});
</script>
